package com.abel.bigwater.wflow

import com.abel.bigwater.model.ticket.TicketParam
import com.abel.bigwater.wflow.mapper.TicketMapper
import com.abel.bigwater.wflow.mapper.UserRoleMapper
import com.alibaba.fastjson.JSON
import org.junit.Test
import org.junit.runner.RunWith
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner

@SpringBootTest
@RunWith(SpringRunner::class)
class MapperTests {
    @Autowired
    var userRoleMapper: UserRoleMapper? = null

    @Autowired
    var ticketMapper: TicketMapper? = null

    @Test
    fun testUserRole() {
        val ulist = userRoleMapper!!.listUser(null, null, null)
        lgr.info("users : ${ulist.size}")

        val uroles = ulist.filter { it.roles?.size ?: 0 > 1 }
        lgr.info("users with more than 1 role: ${uroles.size}.\n${JSON.toJSONString(uroles, true)}")
    }

    @Test
    fun testListTicket() {
        val tlist = ticketMapper!!.listTicket(TicketParam().apply { firmId = "23" })
        lgr.info("ticket count: ${tlist?.size}")
    }

    companion object {
        private val lgr = LoggerFactory.getLogger(MapperTests::class.java)
    }
}